﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BASE;

public partial class Admin_timkiemsinhvien : BasePage
{
    string pageSize = "30";
    protected void Page_Load(object sender, EventArgs e)
    {
        //check quyen vao trang

        if (Utils.getIntSession("userid") == 0)
        {
            Response.Redirect("/admin/login.aspx");
        }
        Session["trang"] = Constants.ADMIN_SINHVIEN;
    }
    protected void btn_luu_Click(object sender, EventArgs e)
    {
        GetCustomersPageWise(1);
    }
    void bindata(int pageIndex, string pageSize)
    {

        busSinhVien busSV = new busSinhVien();

        List<entSinhVien> lst = new List<entSinhVien>();
        lst = busSV.search(txt_malop.Text,txt_masinhvien.Text,txt_t.Text, pageIndex, pageSize);
        gr_sv.DataSource = lst;
        gr_sv.DataBind();
        int recordCount = 0;
        if (lst.Count > 0)
        {
            recordCount = int.Parse(lst[0].recordCount);
        }
        else
        {
            MessenBox(1, "Không có sinh viên");
        }
        PopulatePager(recordCount, pageIndex);

    }
    #region  ========phan trang=======
    protected void PageSize_Changed(object sender, EventArgs e)
    {
        this.GetCustomersPageWise(1);
    }

    private void GetCustomersPageWise(int pageIndex)
    {
        bindata(pageIndex, pageSize);
    }
    protected void Page_Changed(object sender, EventArgs e)
    {
        int pageIndex = int.Parse((sender as LinkButton).CommandArgument);
        this.GetCustomersPageWise(pageIndex);
    }

    private void PopulatePager(int recordCount, int currentPage)
    {
        double dblPageCount = (double)((decimal)recordCount / decimal.Parse(pageSize));
        int pageCount = (int)Math.Ceiling(dblPageCount);
        List<ListItem> pages = new List<ListItem>();
        if (pageCount > 0)
        {
            pages.Add(new ListItem("First", "1", currentPage > 1));
            for (int i = 1; i <= pageCount; i++)
            {
                pages.Add(new ListItem(i.ToString(), i.ToString(), i != currentPage));
            }
            pages.Add(new ListItem("Last", pageCount.ToString(), currentPage < pageCount));
        }
        rptPager.DataSource = pages;
        rptPager.DataBind();
    }

    #endregion
}